<?php
	/**
	 * <version greek="beta" major="1" minor="0">Cochin Splash Hen</version>
	 * <author email="njones@art-k-tec.com">Nika Jones</author>
	 * <copyright start="2007">Art-k-tec Systems, LLC</copyright>
	 * <license type="Apache2.0" href="http://www.opensource.org/licenses/apache2.0.php">Apache License, Version 2.0</license>
	 * <summary>
	 *    This provides a consistant interface for filtering or encoding data.
	 *    With easy to remember names for MySQL, URL and such. It also helps
	 *    with keeping encoding seperate from escaping.
	 * <summary>
	 */
	class bFilter {
	
		const MYSQL	=1;
		const URL =2;
		const HTML =4;
		const ENTITY_DECIMAL =8;
		const ENTITY_HTML =16;
		const RFC3986 =32;
	
		public function Input($sData, $wType =self::HTML, $sAllowableTags =null) {
			
			if($wType & self::HTML) {
			
				$sData =strip_tags($sData, $sAllowableTags);
			}
			
			if($wType & self::ENTITY_DECIMAL) {
				
				$sData =mb_encode_numericentity ($sData, array (0x80, 0xffff, 0, 0xffff), 'UTF-8');
			}
			
			if($wType & self::URL) {
			
				$sData =rawurlencode($sData);
				if($wType & self::RFC3986) {
					
					$a =array('replace'=>array('+', '%7E'), 'with'=>array(' ', '-'));
					$sData =str_replace($a['replace'], $a['with'], $sData);
				}
			}

			if($wType & self::MYSQL) {
			
				$sData =mysql_escape_string($sData);
			}
						
			return $sData;
		}
		
		public function Output($sData, $wType =0) {
			
			if($wType & self::MYSQL) {
			
				$sData =stripslashes($sData);
			}
			
			if($wType & self::URL) {
			
				$sData =rawurldecode($sData);
			}
			
			if($wType & self::ENTITY_DECIMAL) {
			
				$sData =mb_decode_numericentity ($sData, array (0x80, 0xffff, 0, 0xffff), 'UTF-8');
			}
			
			return $sData;
		}
				
		private function ConvertFromEntity($sLine) {
		
			$aMap = array(0x0, 0x10000, 0, 0xfffff);
 			return mb_decode_numericentity($sLine, $aMap, 'UTF-8');
		}
	}
	
	

?>